package com.jung.administrator.dao.impl;

import java.util.List;

import com.jung.administrator.dao.AdministratorDao;
import com.jung.administrator.model.Administrator;
import com.jung.common.HibernateEntityManagerImpl;
import com.jung.exception.SkeletonException;
import com.jung.exception.SkeletonSystemException;

public class AdministratorDaoImpl extends HibernateEntityManagerImpl<Administrator> implements AdministratorDao {

	public boolean add(Administrator administrator) {
		try {
			super.save(administrator);
		} catch (SkeletonSystemException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean updateAdmin(Administrator administrator) {
		
		try {
			super.update(administrator);
		} catch (SkeletonSystemException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public Administrator getByUserName(String userName) {
		
		String hql = "from Administrator where userName = '"+userName+"'";
		Object object = null;
		try {
			List administratorList =super.executeHql(hql); 
			if(administratorList.size()<1){
				return null;
			}
			object = administratorList.get(0);
		} catch (SkeletonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Administrator administrator = (Administrator)object;
		return administrator;
	}

	

}
